const menu = {
    home : {
        title : '首页',
        route : '/'
    },
    goods : {
        title : '商品',
        route : '/goods/list',
        subs : {
            list: {
                title : '查看商品',
                route : '/goods/list'
            },
            new: {
                title : '商品发布',
                route : '/goods/new'
            }
        }
    },
    setting : {
        title : '设置',
        route : '/setting/store',
        subs : {
            list: {
                title : '店铺信息',
                route : '/setting/store'
            },
            new: {
                title : '物流模板',
                route : '/setting/store'
            }
        }
    }
};

const router = [
    {
        path : '/',
        meta : menu.home,
        component : require('../../component/seller/Console/Index.vue')
    },
    {
        path : '/goods/new',
        meta : menu.goods.subs.new,
        component : require('../../component/seller/Goods/Edit.vue')
    },
    {
        path : '/goods/list',
        meta : menu.goods.subs.list,
        component : require('../../component/seller/Goods/List.vue')
    },
    {
        path : '/setting/store',
        meta : menu.setting.subs.list,
        component : require('../../component/seller/Setting/Store.vue')
    }
];

for(let i in menu){
    if('subs' in menu[i]){
        for(let val in menu[i].subs)
            menu[i].subs[val].parent = menu[i];
    }
}

const beforeRouteEnter  = function(to, from, next) {
    for(let i in menu){
        menu[i].active = false;
        if('subs' in menu[i]){
            for(let val in menu[i].subs)
                menu[i].subs[val].active = false;
        }
    }
    to.meta.active = true;
    if('parent' in to.meta)
        to.meta.parent.active = true;
    next();
};


for(let item of router){
    item.beforeEnter = beforeRouteEnter;
}

export default {
    router : router,
    menu : menu
};